/**
 * Created by yunpeng on 2015/4/16.
 */
/**
 * Created by yunpeng on 2015/4/13.
 */
$('#orderdg').datagrid({
    url:'/admin/ordersList',
    //border : false,
    rownumbers: true,
    idField : 'id',
    pagination : true,
    sortName : 'createtime',//默认排序的列
    sortOrder: 'desc',
    pageSize : 10,
    pageList : [ 10, 20, 40, 80 ],
    fitColumns : true,
    fit : true,
    checkOnSelect : false,
    selectOnCheck : true,
    striped: true,//条纹交替
    columns:[[
        {field:'',checkbox:true},
        {field:'orderno',title:'订单号',width:150,align:'center'},
        {field:'type',title:'发车类型',width:200,align:'center',formatter : function(value, rowData, rowIndex) {
            if(value==1){
                return '<span style="color: #24748f">零散车辆</span>';
            }else if(value==2){
                return '整板车辆';
            }

        }},
        /*{field:'carnum',title:'品牌',width:150,align:'center'},
         {field:'num',title:'型号',width:150,align:'center'},*/
        {field:'startstation',title:'始发地',width:250,align:'center'},
        {field:'endstation',title:'目的地',width:250,align:'center'},
        {field:'starttime',title:'出发日期',width:200,align:'center'},
        {field:'endtime',title:'到达日期',width:200,align:'center'},
        {field:'phone',title:'发车人手机',width:200,align:'center'},
        {field:'status',title:'发车状态',width:200,align:'center',formatter : function(value, rowData, rowIndex) {
            if(value==1){
                return '<span style="color: #24748f">新发布</span>';
            }else if(value==2){
                return '已接受';
            }else if(value==3){
                return '已评价';
            }else if(value==4){
                return '取消发布';
            }else if(value==5){
                return '取消订单';
            }

        }},
        {field:'createtime',title:'发布日期',width:200,align:'center'}

    ]],
    toolbar : '#otb'
});

function searchOrderList(){
    $('#orderdg').datagrid('load',{
        date1: $('#odate1').datebox('getValue'),
        date2: $('#odate2').datebox('getValue'),
        phone: $('#ophone').textbox('getValue'),
        orderno: $('#orderno').textbox('getValue'),
        ostatus:$('#ostatus').combobox('getValue')
    });
}

var inforid;
function viewOrder(){
    var rows = $('#orderdg').datagrid('getChecked');
    if (rows.length == 1) {
        inforid = rows[0].id;
        //动态加载
        var detailWindow = $('<div/>')
            .dialog(
            {
                width : document.body.clientWidth*0.7,
                height : document.body.clientHeight,
                href : '/admin/views/orderdetail.html',
                modal : true,
                title : '承运方报价',
                maximizable:true,
                cache:false,
                minimized:true,
                buttons : [{
                    text : '关&nbsp;&nbsp;闭',
                    width : 60,
                    handler : function() {
                        detailWindow.dialog('close');
                    }
                }],
                onClose : function() {
                    $('#orderdg').datagrid('uncheckAll');// 取消选中的所有记录
                    $(this).dialog('destroy');//动态加载一定要销毁
                },
                //加载数据，用onLoad，不是用onOpen
                onLoad : function() {

                }
            });
    } else {
        $.messager.alert('提示', '请选择1条记录', 'error');
    }
}

